package com.explorati.interview.interview.chapterfifteen;

/**
 * 回文数：例如16461 可以用StringBuffer，但是不用效率更高
 * 
 * @author explorati
 *
 */
public class CircleNum {

	public static void main(String[] args) {
		int count = 0;
		for (int i = 10; i < 10000; i++) {
			if (isCircleNum1(i)) {
				System.out.print(i + "\t");
				count++;
				if (count % 5 == 0) {
					System.out.println();
				}
			}

		}
	}

	public static boolean isCircleNum(int num) {
		int oldNum = num;
		int temp = 0;
		while (num > 0) {
			temp = temp * 10 + num % 10;
			num = num / 10;
		}
		return temp == oldNum;
	}

	public static boolean isCircleNum1(int num) {
		Integer i = Integer.valueOf(num);
		String str = i.toString();
		StringBuffer sb = new StringBuffer(str);
		StringBuffer reverseNum = sb.reverse();
		String reverseNum1 = reverseNum.toString();
		int reverseNum2 = Integer.parseInt(reverseNum1);
		return reverseNum2 == num;

	}
}
